package com.fap.weixin;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fap.search.executor.DataRow;
import com.fap.search.parameter.IParameter;
import com.fap.search.parameter.impl.PString;
import com.fap.search.service.ISearchService;

@Controller
public class QuickSearch {

	@Autowired
	private ISearchService service;
	
    @RequestMapping(value="/search.do",method=RequestMethod.GET)  
    public String showMessage(HttpServletRequest request, HttpServletResponse response,Object handle, Model m) {
    	
    	PString strParam = new PString("bo_property_id");
    	strParam.setValue("2");
    	try {
			List<DataRow> dsResult = service.invoke("sql-1", new IParameter[]{strParam});
			DataRow dr = dsResult.get(0);
			String tmp="";
			for(int i=0; i<dr.columnCount(); i++){
				tmp = tmp+dr.getColumnName(i)+":"+dr.get(i).toString()+" ";
			}
//	    	m.addAttribute("result",dsResult.get(0).get("field_name").toString());
	    	m.addAttribute("result",tmp);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	System.out.println("search............");
    	
//    	m.addAttribute("result","result 1234");
    	return "demo";
    }	
}
